import Opt from '@/components/dt/info/Opt.js'
import businessCommonMgr from '@/biz/businessReport/businessCommon'
import houseOpt from '@/biz/option/house.js'

let _this = null
let companys = []
class SearchOpt extends Opt {

  constructor(vm) {
    _this = vm
    super()
    this.build()
  }

  getCompany() {
    let opt = {
      title: '组织筛选',
      key: 'orgId',
      placeholder: '全部',
      tree: {
        options: companys,
      }
    }
    let params = {
      isTwoLevel: true,
    }
    businessCommonMgr
      .getOrganizationTree(params)
      .then((res) => {
        companys = res
        opt.tree.options = companys
      })
    return opt
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
      this.getCompany(),
      houseOpt.create({
        title: '所属案场',
        to: (info) => {
          return {
            housesId: info.housesId || ''
          }
        }
      }),
    ]
  }
}

export default SearchOpt